package com.pfzy.ui

import android.app.Activity
import java.lang.ref.WeakReference

/**
 * 前台Activity管理类
 */
class ForegroundActivityManager {
    private var currentActivityWeakRef: WeakReference<Activity>? = null
    private var mIsActive: Boolean = false

    companion object {
        val TAG = "ForegroundActivityManager"
        private val instance = ForegroundActivityManager()

        @JvmStatic
        fun getInstance(): ForegroundActivityManager {
            return instance
        }
    }

    fun getCurrentActivity(): Activity? {
        var currentActivity: Activity? = null
        if (currentActivityWeakRef != null) {
            currentActivity = currentActivityWeakRef?.get()
        }
        return currentActivity
    }

    fun setCurrentActivity(activity: Activity) {
        currentActivityWeakRef = WeakReference(activity)
    }

    fun setActive(isActive: Boolean) {
        mIsActive = isActive
    }

    fun getActive(): Boolean = mIsActive
}
